﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ItemTemplateWizards.UI;
using System.Windows.Forms;

namespace ItemTemplateWizards
{
    class FeatureItemTemplateWizard : Microsoft.VisualStudio.TemplateWizard.IWizard
    {
        private bool m_includeFeatureReceiver;

        #region IWizard Members

        public void BeforeOpeningFile(EnvDTE.ProjectItem projectItem)
        {
            
        }

        public void ProjectFinishedGenerating(EnvDTE.Project project)
        {
        }

        public void ProjectItemFinishedGenerating(EnvDTE.ProjectItem projectItem)
        {
        }

        public void RunFinished()
        {
            
        }

        public void RunStarted(object automationObject, Dictionary<string, string> replacementsDictionary, Microsoft.VisualStudio.TemplateWizard.WizardRunKind runKind, object[] customParams)
        {
            try
            {
                FeatureInformation form = new FeatureInformation();
                DialogResult dr = form.ShowDialog();

                replacementsDictionary.Add("$featurescope$", form.FeatureScope.ToString());
                m_includeFeatureReceiver = form.IncludeFeatureReceiver;

                replacementsDictionary.Add("$includereceiver$", form.IncludeFeatureReceiver.ToString());
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);
            }
        }

        public bool ShouldAddProjectItem(string filePath)
        {
            if (filePath.Contains("FeatureReceiver.cs") && !m_includeFeatureReceiver)
                return false;
            else if (filePath.Contains("FeatureWithReceiver.xml") && !m_includeFeatureReceiver)
                return false;
            else if (filePath.Contains("FeatureWithoutReceiver.xml") && m_includeFeatureReceiver)
                return false;
            else
                return true;
        }

        #endregion
    }
}
